<?php
class Agencies extends Admin_Controller
{
	function __construct()
	{
		parent::__construct();
	}
	
	function index()
	{
		$data['agencies'] = new Agency;
		$data['agencies']->order_by('id','desc')->get_page();
		$this->template->build('admin/agency_index',$data);
	}
	
	function form($id = NULL)
	{	
		$data['agency'] = new Agency($id);
		$data['categories'] = new Category;
		$data['categories']->order_by('id','asc')->get();
		$this->template->build('admin/agency_form',$data);	
	}
	
	function save($id=FALSE)
	{
		if($_POST)
		{
			$agency = new Agency($id);
			$agency->user_id = $this->session->userdata('id');
			$agency->from_array($_POST);
			$agency->save();
			
			set_notify('success', lang('save_data_complete'));
		}
		redirect('agencies/admin/agencies');
	}
	
	function delete($id)
	{
		if($id)
		{
			$agency = new Agency($id);
			$agency->picture->delete_all();
			$agency->delete();
			set_notify('success', lang('delete_data_complete'));
		}
		redirect('agencies/admin/agencies/');
	}
	
	
	
}
?>